import 'package:PollOnLine/values/MyColors.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../r.dart';
import 'welcome_logic.dart';

class WelcomePage extends StatefulWidget {
  final String title;

  const WelcomePage({Key? key, required this.title}) : super(key: key);

  @override
  State<WelcomePage> createState() => _WelcomePageState();
}

class _WelcomePageState extends State<WelcomePage> {
  final logic = Get.put(WelcomeLogic());
  final state = Get.find<WelcomeLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Stack(
        children: [
          Align(
            alignment: Alignment.topCenter,
            child: Padding(
                padding: EdgeInsets.only(top: 70.r),
                child: Column(
                  children: [
                    Image.asset(R.assetsImgWelcomeIcon1, width: 150.r),
                    Padding(
                      padding: EdgeInsets.only(top: 35.r),
                      child: Image.asset(R.assetsImgWelcomeIcon2, height: 31.r),
                    ),
                  ],
                )),
          ),
          Align(
            alignment: Alignment.bottomCenter,
            child: Padding(
              padding: EdgeInsets.only(bottom: 40.r),
              child: Image.asset(R.assetsImgWelcomeIcon3, height: 30.r),
            ),
          ),
          // 隐私协议弹窗
          Obx(() {
            return Visibility(
              visible: state.visible.value,
              child: Dialog(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(4.r),
                ),
                child: IntrinsicHeight(
                  child: SizedBox(
                    width: 500.r,
                    child: Column(
                      children: [
                        Container(
                          margin: EdgeInsets.only(top: 20.r),
                          child: Center(
                            child: Text("欢迎使用面访调查", style: TextStyle(color: Colors.indigo, fontSize: 16.r)),
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.all(15.r),
                          height: 230.r,
                          child: SingleChildScrollView(
                            child: Column(
                              children: [
                                RichText(
                                    text: TextSpan(children: [
                                  TextSpan(
                                      text: "《面访调查隐私权限政策》",
                                      style: TextStyle(color: Colors.indigo, fontSize: 14.r),
                                      recognizer: TapGestureRecognizer()
                                        ..onTap = () {
                                          logic.dialogOnTap();
                                        }),
                                  TextSpan(
                                      text: "将帮助您了解如何保护您的个人信息和隐私，以及面访调查如何收集、处理您的个人信息。", style: TextStyle(color: MyColors.FF666666, fontSize: 14.r))
                                ])),
                                SizedBox(
                                  height: 10.r,
                                ),
                                Text("我们可能会申请系统设备权限，以及收集其他设备信息如网络设备硬件地址、日志信息等，用于识别设备，进行信息推送。但需要您的同意。",
                                    style: TextStyle(color: MyColors.FF666666, fontSize: 14.r)),
                                SizedBox(
                                  height: 10.r,
                                ),
                                Text("我们可能会申请麦克风和摄像头权限，用于语音或者视频通讯。但需要您的同意。", style: TextStyle(color: MyColors.FF666666, fontSize: 14.r)),
                                SizedBox(
                                  height: 10.r,
                                ),
                                Text("上述权限以及相册（存储）、GPS、悬浮窗等权限均不会默认或强制开启收集信息。", style: TextStyle(color: MyColors.FF666666, fontSize: 14.r)),
                              ],
                            ),
                          ),
                        ),
                        const Divider(height: 1.0, color: MyColors.FFE6E6E6),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: [
                            TextButton(
                              style: TextButton.styleFrom(
                                padding: const EdgeInsets.all(0),
                                minimumSize: Size(100.r, 40.r),
                              ),
                              onPressed: () {
                                logic.dialogCallbackCancel();
                              },
                              child: Text("退出应用", style: TextStyle(color: MyColors.FF333333, fontSize: 14.r)),
                            ),
                            Container(
                              width: 0.5,
                              height: 40,
                              color: MyColors.FFDDDDDD,
                            ),
                            TextButton(
                              style: TextButton.styleFrom(
                                padding: const EdgeInsets.all(0),
                                minimumSize: Size(100.r, 40.r),
                              ),
                              onPressed: () {
                                Get.back();
                                logic.dialogCallbackOk();
                              },
                              child: Text("同意", style: TextStyle(fontSize: 14.r, fontWeight: FontWeight.w600)),
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                ),
              ),
            );
          }),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<WelcomeLogic>();
    super.dispose();
  }
}
